import React, { Component } from 'react';
import { DatePicker, Input, Select, Button } from 'antd';
import { setTimeSection } from '@/utils';

const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
const Option = Select.Option;

export const commonConfig = args => {
    const { data = {}, mapSource = [], disabled = false, options = {} } = args;
    return [
        {
            label: '时间段',
            field: 'time',
            layout: null,
            className: '',
            Component: props => (
                <RangePicker
                    {...props}
                    style={{ width: '240px' }}
                    disabled={disabled || props.disabled}
                />
            ),
            initialValue: setTimeSection(data.time || [], 7),
            rules: null,
            updateInitialValue({ quickSelect }) {
                if (quickSelect) {
                    return setTimeSection([], quickSelect);
                }
            },
            isDisabled() {},
            noRender() {}
        },
        {
            label: '快捷选择',
            field: 'quickSelect',
            layout: null,
            className: '',
            Component: props => (
                <Select
                    {...props}
                    disabled={disabled || props.disabled}
                    style={{ width: '100px' }}
                    placeholder="请选择..."
                >
                    <Option value={7}>最近7天</Option>
                    <Option value={3}>最近3天</Option>
                </Select>
            ),
            initialValue: data.quickSelect || 7,
            rules: null,
            updateInitialValue() {},
            isDisabled() {},
            noRender() {}
        },
        {
            label: '关键字',
            field: 'keycode',
            layout: null,
            className: '',
            Component: props => (
                <Input
                    {...props}
                    style={{ width: '160px' }}
                    disabled={disabled || props.disabled}
                    placeholder="请输入..."
                />
            ),
            initialValue: data.keycode || undefined,
            rules: null,
            updateInitialValue() {},
            isDisabled() {},
            noRender() {}
        },
        {
            label: '性别',
            field: 'gender',
            layout: null,
            className: '',
            Component: props => (
                <Select
                    {...props}
                    disabled={disabled || props.disabled}
                    style={{ width: '90px' }}
                    placeholder="请选择..."
                >
                    <Option value={1}>男</Option>
                    <Option value={0}>女</Option>
                </Select>
            ),
            initialValue: data.gender || undefined,
            rules: null,
            updateInitialValue() {},
            isDisabled() {},
            noRender() {}
        },
        {
            label: '年龄',
            field: 'age',
            layout: null,
            className: '',
            Component: props => (
                <Input
                    {...props}
                    style={{ width: '160px' }}
                    disabled={disabled || props.disabled}
                    placeholder="请输入..."
                />
            ),
            initialValue: data.age || undefined,
            rules: null,
            updateInitialValue() {},
            isDisabled() {},
            noRender() {}
        },
        {
            label: '工作岗位',
            field: 'work',
            layout: null,
            className: '',
            Component: props => (
                <Input
                    {...props}
                    style={{ width: '160px' }}
                    disabled={disabled || props.disabled}
                    placeholder="请输入..."
                />
            ),
            initialValue: data.work || 'WEB前端',
            rules: null,
            updateInitialValue() {},
            isDisabled() {},
            noRender() {}
        },
    ];
};

export default {
    commonConfig
};
